home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-04 | 24.8 KB | 792 lines | [TEXT/CWIE] |
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
- // help.c
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
-
- // …………………………………………………………………………………………………………………………………………………………………………………………………………… includes
-
- #include <Dialogs.h>
- #include <ToolUtils.h>
- #include <Resources.h>
-
- // ……………………………………………………………………………………………………………………………………………………………………………………………………………… defines
-
- #define rHelpModal 128
- #define iOK 1
- #define iTextUserItem 2
- #define iScrollBar 3
- #define iPopupMenu 4
- #define iButtonUserItem 5
- #define rAlert 129
- #define kTextInset 4
- #define kReturn 0x0D
- #define kEnter 0x03
-
- // This block of defines will need to be changed to accommodate the ID of the 'TEXT'/
- // 'styl' resource associated with each of your popup menu items, and the starting 'PICT'
- // ID for the 'PICT's (if any) associated with each 'TEXT' resource.
-
- #define rTextIntroduction 128
- #define rTextCreatingText 129
- #define rTextModifyHelp 130
- #define rTextAboutCricket 131
- #define rPictIntroductionBase 128
- #define rPictCreatingTextBase 129
- #define rPictAboutCricketBase 131
-
- // …………………………………………………………………………………………………………………………………………………………………………………………………………… typedefs
-
- typedef struct
- {
- Rect bounds;
- PicHandle pictureHdl;
- } pictInfoRec;
-
- typedef struct
- {
- TEHandle editRecHdl;
- ControlHandle scrollbarHdl;
- SInt16 pictCount;
- pictInfoRec *pictInfoRecPtr;
- } docRecord, ** docRecordHandle;
-
- // ……………………………………………………………………………………………………………………………………………………………………………………… global variables
-
- SInt16 gTextResourceID;
- SInt16 gPictResourceBaseID;
- RgnHandle gSavedClipRgn = nil;
-
- // ……………………………………………………………………………………………………………………………………………………………………………… function prototypes
-
- void doHelp (void);
- void closeHelp (DialogPtr,GrafPtr);
- pascal void drawHelp (DialogPtr,SInt16);
- Boolean getText (DialogPtr,SInt16,Rect);
- Boolean getPictureInfo (DialogPtr,SInt16);
- void handleScrollBar (DialogPtr,SInt16,Point);
- pascal void actionProcedure (ControlHandle,SInt16);
- void scrollTextAndPicts (DialogPtr);
- void drawPictures (DialogPtr,Rect *);
- pascal Boolean helpDialogFilter (DialogPtr,EventRecord *,SInt16 *);
- pascal void drawButtonOutline (DialogPtr,SInt16);
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ doHelp
-
- // Open dialog and create a document record for the dialog, install draw functions, store
- // scroll bar handle in document record, create a style-aware edit record, get the text
- // and picture info relating to popup menu item No 1, do the ModalDialog loop (in which
- // popup menu selections are detected and handled), and close down on an OK button hit.
-
- void doHelp(void)
- {
- DialogPtr modalDlgPtr;
- docRecordHandle docRecHdl;
- GrafPtr oldPort;
- SInt16 itemType,itemHit, menuItem;
- Handle itemHdl;
- Rect userItemRect, destRect, viewRect, itemRect;
- ModalFilterUPP helpDialogFilterUPP; // PowerPC
- UserItemUPP drawHelpUPP; // PowerPC
- UserItemUPP drawButtonOutlineUPP; // PowerPC
-
- helpDialogFilterUPP = NewModalFilterProc((ProcPtr) helpDialogFilter); // PowerPC
- drawHelpUPP = NewUserItemProc((ProcPtr) drawHelp); // PowerPC
- drawButtonOutlineUPP = NewUserItemProc((ProcPtr) drawButtonOutline); // PowerPC
-
- if(!(modalDlgPtr = GetNewDialog(rHelpModal,nil,(WindowPtr) -1)))
- {
- ParamText("\pCannot open help dialog",nil,nil,nil);
- StopAlert(rAlert,nil);
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- return;
- }
-
- if(!(docRecHdl = (docRecordHandle) NewHandle(sizeof(docRecord))))
- {
- ParamText("\pCannot get memory for required for help document record",nil,nil,nil);
- StopAlert(rAlert,nil);
- DisposDialog(modalDlgPtr);
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- return;
- }
-
- SetWRefCon(modalDlgPtr,(SInt32) docRecHdl);
-
- GetPort(&oldPort);
- SetPort(modalDlgPtr);
-
- GetDialogItem(modalDlgPtr,iButtonUserItem,&itemType,&itemHdl,&userItemRect);
- SetDialogItem(modalDlgPtr,iButtonUserItem,itemType,(Handle) drawButtonOutlineUPP,
- &userItemRect);
-
- GetDialogItem(modalDlgPtr,iTextUserItem,&itemType,&itemHdl,&userItemRect);
- SetDialogItem(modalDlgPtr,iTextUserItem,itemType,(Handle) drawHelpUPP,&userItemRect);
-
- GetDialogItem(modalDlgPtr,iScrollBar,&itemType,&itemHdl,&itemRect);
- (*docRecHdl)->scrollbarHdl = (ControlHandle) itemHdl;
-
- InsetRect(&userItemRect,kTextInset,kTextInset / 2);
- destRect = viewRect = userItemRect;
- (*docRecHdl)->editRecHdl = TEStylNew(&destRect,&viewRect);
-
- (*docRecHdl)->pictInfoRecPtr = nil;
-
- // The value assigned to the first two global variables will need to be changed to the
- // constants representing the ID of the 'TEXT" resource associated with the first popup
- // menu item and the base ID of the pictures (if any) associated with that 'TEXT'
- // resource.
-
- gTextResourceID = rTextIntroduction;
- gPictResourceBaseID = rPictIntroductionBase;
-
- if(!(getText(modalDlgPtr,gTextResourceID,viewRect)))
- {
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- closeHelp(modalDlgPtr,oldPort);
- return;
- }
- if(!(getPictureInfo(modalDlgPtr,gPictResourceBaseID)))
- {
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- closeHelp(modalDlgPtr,oldPort);
- return;
- }
-
- gSavedClipRgn = NewRgn();
-
- ShowWindow(modalDlgPtr);
-
- do
- {
- ModalDialog((ModalFilterUPP) helpDialogFilterUPP,&itemHit);
-
- if(itemHit == iPopupMenu)
- {
- SetControlValue((*docRecHdl)->scrollbarHdl,0);
-
- GetDialogItem(modalDlgPtr,iPopupMenu,&itemType,&itemHdl,&itemRect);
- menuItem = GetControlValue((ControlHandle) itemHdl);
-
- // This switch is the final modification you require. You need one case for each
- // item in your popup menu. At each case, you need to assign the ID of the
- // relevant 'TEXT'/'styl' resource to gTextResourceID and, where appropriate, the
- // base 'PICT' resource ID for the 'PICT' resources associated with that
- // particular 'TEXT' resource.
-
- switch(menuItem)
- {
- case 1:
- gTextResourceID = rTextIntroduction;
- gPictResourceBaseID = rPictIntroductionBase;
- break;
-
- case 2:
- gTextResourceID = rTextCreatingText;
- gPictResourceBaseID = rPictCreatingTextBase;
- break;
-
- case 3:
- gTextResourceID = rTextModifyHelp;
- break;
-
- case 5:
- gTextResourceID = rTextAboutCricket;
- gPictResourceBaseID = rPictAboutCricketBase;
- break;
- }
-
- if(!(getText(modalDlgPtr,gTextResourceID,viewRect)))
- {
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- closeHelp(modalDlgPtr,oldPort);
- return;
- }
- if(!(getPictureInfo(modalDlgPtr,gPictResourceBaseID)))
- {
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- closeHelp(modalDlgPtr,oldPort);
- return;
- }
-
- drawPictures(modalDlgPtr,&viewRect);
- }
-
- } while(itemHit != iOK);
-
- DisposeRoutineDescriptor(helpDialogFilterUPP); // PowerPC
- DisposeRoutineDescriptor(drawHelpUPP); // PowerPC
- DisposeRoutineDescriptor(drawButtonOutlineUPP); // PowerPC
- closeHelp(modalDlgPtr,oldPort);
-
- return;
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ closeHelp
-
- // If they exist, dispose of saved clip region, the text edit record, the array of
- // pictInfoRec records, and the picture records. Then dispose of the dialog's document
- // record and, finally, the dialog record.
-
- void closeHelp(DialogPtr modalDlgPtr,GrafPtr oldPort)
- {
- docRecordHandle docRecHdl;
- TEHandle editRecHdl;
- SInt16 a;
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- editRecHdl = (*docRecHdl)->editRecHdl;
-
- if(gSavedClipRgn)
- DisposeRgn(gSavedClipRgn);
-
- if((*docRecHdl)->editRecHdl)
- TEDispose((*docRecHdl)->editRecHdl);
-
- if((*docRecHdl)->pictInfoRecPtr)
- {
- for(a=0;a<(*docRecHdl)->pictCount;a++)
- ReleaseResource((Handle) (*docRecHdl)->pictInfoRecPtr[a].pictureHdl);
- DisposPtr((Ptr) (*docRecHdl)->pictInfoRecPtr);
- }
-
- DisposeHandle((Handle) docRecHdl);
- DisposDialog(modalDlgPtr);
-
- SetPort(oldPort);
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ drawHelp
-
- // Installed in a user item. Called whenever dialog gets update event. Draws some
- // shadow boxes, the rectangle in which text and picts will be displayed, and the popup
- // menu title. More importantly, calls TEUpdate to redraw the text, and drawPictures to
- // draw the pictures.
-
- pascal void drawHelp(DialogPtr modalDlgPtr,SInt16 theItem)
- {
- PenState oldPenState;
- Handle itemHdl;
- Rect itemRect, viewRect, theRect;
- SInt16 itemType;
- docRecordHandle docRecHdl;
- TEHandle editRecHdl;
- RGBColor whiteColour = { 0xFFFF, 0xFFFF, 0xFFFF };
- RGBColor greyColour = { 0x4444, 0x4444, 0x4444 };
- RGBColor blackColour = { 0x0000, 0x0000, 0x0000 };
-
- GetPenState(&oldPenState);
-
- GetDialogItem(modalDlgPtr,iTextUserItem,&itemType,&itemHdl,&itemRect);
- InsetRect(&itemRect,1,1);
-
- RGBBackColor(&whiteColour);
- FillRect(&itemRect,&qd.white);
-
- InsetRect(&itemRect,-1,-1);
- FrameRect(&itemRect);
-
- // Draw shadow boxes around the dialog and around the internal text box.
-
- PenSize(2,2);
- RGBForeColor(&whiteColour);
- SetRect(&theRect,0,0,449,385);
- FrameRect(&theRect);
- RGBForeColor(&greyColour);
- MoveTo(theRect.right - 2,theRect.top + 2);
- LineTo(theRect.right - 2,theRect.bottom - 2);
- MoveTo(theRect.left + 2,theRect.bottom - 2);
- LineTo(theRect.right - 2,theRect.bottom - 2);
-
- InsetRect(&itemRect,-3,-3);
- itemRect.right += 16;
- RGBForeColor(&greyColour);
- FrameRect(&itemRect);
- RGBForeColor(&whiteColour);
- MoveTo(itemRect.right - 2,itemRect.top + 2);
- LineTo(itemRect.right - 2,itemRect.bottom - 2);
- MoveTo(itemRect.left + 2,itemRect.bottom - 2);
- LineTo(itemRect.right - 2,itemRect.bottom - 2);
-
- // Draw the popup menu title. (The title has been omitted from the control resource.
- // Drawing the title here means that the background will be drawn in grey rather
- // than white.
-
- TextFont(0);
- MoveTo(110,32);
- RGBForeColor(&blackColour);
- DrawString("\pHelp Topic:");
-
- // The important stuff - draw the text and the pictures.
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- editRecHdl = (*docRecHdl)->editRecHdl;
- viewRect = (*editRecHdl)->viewRect;
-
- TEUpdate(&viewRect,editRecHdl);
- drawPictures(modalDlgPtr,&viewRect);
-
- SetPenState(&oldPenState);
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ getText
-
- // Delete any existing text in the text edit record and set the scroll bar control value
- // to 0. Get 'TEXT' and 'styl' resources relating to the pop menu item chosen, insert
- // the text in the edit text record, release the 'TEXT' and 'styl' resources, highlight
- // the scroll bar and set the scroll bar control maximum value if the text height is
- // greater than the height of the view rectangle, otherwise just un-highlight the scroll
- // bar.
-
- Boolean getText(DialogPtr modalDlgPtr,SInt16 textResourceID,Rect viewRect)
- {
- docRecordHandle docRecHdl;
- TEHandle editRecHdl;
- Handle helpTextHdl;
- StScrpHandle stylScrpRecHdl;
- SInt16 numberOfLines, heightOfText, heightToScroll;
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- editRecHdl = (*docRecHdl)->editRecHdl;
-
- TESetSelect(0,32767,editRecHdl);
- TEDelete(editRecHdl);
-
- (*editRecHdl)->destRect = (*editRecHdl)->viewRect;
- SetControlValue((*docRecHdl)->scrollbarHdl,0);
-
- helpTextHdl = GetResource('TEXT',textResourceID);
- if(helpTextHdl == nil)
- {
- ParamText("\pCannot get 'TEXT' resource for help dialog",nil,nil,nil);
- StopAlert(rAlert,nil);
- return false;
- }
-
- stylScrpRecHdl = (StScrpHandle) GetResource('styl',textResourceID);
- if(stylScrpRecHdl == nil)
- {
- ParamText("\pCannot get 'styl' resource for help dialog",nil,nil,nil);
- StopAlert(rAlert,nil);
- return false;
- }
-
- TEStylInsert(*helpTextHdl,GetHandleSize(helpTextHdl),stylScrpRecHdl,editRecHdl);
-
- ReleaseResource(helpTextHdl);
- ReleaseResource((Handle) stylScrpRecHdl);
-
- numberOfLines = (*editRecHdl)->nLines;
- heightOfText = TEGetHeight((SInt32) numberOfLines,1,editRecHdl);
-
- if(heightOfText > (viewRect.bottom - viewRect.top))
- {
- heightToScroll = TEGetHeight((SInt32) numberOfLines,1,editRecHdl) -
- (viewRect.bottom - viewRect.top);
- SetControlMaximum((*docRecHdl)->scrollbarHdl,heightToScroll);
- HiliteControl((*docRecHdl)->scrollbarHdl,0);
- }
- else
- {
- HiliteControl((*docRecHdl)->scrollbarHdl,255);
- }
-
- return true;
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ getPictureInfo
-
- // If any currently exist, dispose of existing picture records and pictInfoRect records.
- // Count the number of option_space characters in the text. If none exist, return.
- // Otherwise, create an array of pictInfoRec records, store the handle in the dialog's
- // document record, then stores the PICT handles and picFrames (converted to unscrolled
- // screen coordinates) in the pictInfoRec records.
-
- Boolean getPictureInfo(DialogPtr modalDlgPtr,SInt16 firstPictID)
- {
- docRecordHandle docRecHdl;
- TEHandle editRecHdl;
- Handle textHdl;
- SInt32 offset, textSize;
- SInt16 numberOfPicts, a, lineHeight, fontAscent;
- SInt8 optionSpace[1] = "\xCA";
- pictInfoRec *pictInfoPtr;
- Point picturePoint;
- TextStyle whatStyle;
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
-
- if((*docRecHdl)->pictInfoRecPtr != nil)
- {
- for(a=0;a<(*docRecHdl)->pictCount;a++)
- ReleaseResource((Handle) (*docRecHdl)->pictInfoRecPtr[a].pictureHdl);
-
- DisposePtr((Ptr) (*docRecHdl)->pictInfoRecPtr);
- (*docRecHdl)->pictInfoRecPtr = nil;
- }
-
- (*docRecHdl)->pictCount = 0;
-
- editRecHdl = (*docRecHdl)->editRecHdl;
- textHdl = (*editRecHdl)->hText;
-
- textSize = GetHandleSize(textHdl);
- offset = 0;
- numberOfPicts = 0;
-
- HLock(textHdl);
-
- offset = Munger(textHdl,offset,optionSpace,1,nil,nil);
- while((offset >= 0) && (offset <= textSize))
- {
- numberOfPicts++;
- offset++;
- offset = Munger(textHdl,offset,optionSpace,1,nil,nil);
- }
-
- if(numberOfPicts == 0)
- {
- HUnlock(textHdl);
- return true;
- }
-
- pictInfoPtr = (pictInfoRec *) NewPtr(sizeof(pictInfoRec) * numberOfPicts);
- (*docRecHdl)->pictInfoRecPtr = pictInfoPtr;
-
- offset = 0L;
-
- for(a=0;a<numberOfPicts;a++)
- {
- pictInfoPtr[a].pictureHdl = (PicHandle) GetResource('PICT',firstPictID + a);
- if(pictInfoPtr[a].pictureHdl == nil)
- {
- ParamText("\pCannot get 'PICT' resource for help dialog",nil,nil,nil);
- StopAlert(rAlert,nil);
- return false;
- }
-
- offset = Munger(textHdl,offset,optionSpace,1,nil,nil);
- picturePoint = TEGetPoint((SInt16)offset,editRecHdl);
-
- TEGetStyle(offset,&whatStyle,&lineHeight, &fontAscent,editRecHdl);
- picturePoint.v -= lineHeight;
- offset++;
- pictInfoPtr[a].bounds = (**pictInfoPtr[a].pictureHdl).picFrame;
-
- OffsetRect(&pictInfoPtr[a].bounds,
- (((*editRecHdl)->destRect.right + (*editRecHdl)->destRect.left) -
- (pictInfoPtr[a].bounds.right + pictInfoPtr[a].bounds.left) ) / 2,
- - pictInfoPtr[a].bounds.top + picturePoint.v);
- }
-
- (*docRecHdl)->pictCount = a;
-
- HUnlock(textHdl);
-
- return true;
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ handleScrollBar
-
- // Called by helpDialogFilter to handle mouse-down events in the scroll bar.
-
- void handleScrollBar(DialogPtr modalDlgPtr,SInt16 thePart,Point mouseXY)
- {
- docRecordHandle docRecHdl;
- ControlActionUPP actionProcedureUPP; // PowerPC
-
- actionProcedureUPP = NewControlActionProc((ProcPtr) actionProcedure); // PowerPC
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
-
- if(thePart == inThumb)
- {
- if(TrackControl((*docRecHdl)->scrollbarHdl,mouseXY,nil))
- scrollTextAndPicts(modalDlgPtr);
- }
- else
- TrackControl((*docRecHdl)->scrollbarHdl,mouseXY,(ControlActionUPP) actionProcedureUPP);
-
- DisposeRoutineDescriptor(actionProcedureUPP); // PowerPC
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ actionProcedure
-
- // Called repeatedly by handleScrollBar while the mouse button remains down in the scroll
- // arrows or the gray areas. Determines the distance to scroll, sets the new scoll bar
- // control value accordingly, and calls scrollTextandPicts to effect the scrolling.
-
- pascal void actionProcedure(ControlHandle scrollbarHdl,SInt16 partCode)
- {
- docRecordHandle docRecHdl;
- DialogPtr modalDlgPtr;
- TEHandle editRecHdl;
- SInt16 delta, oldValue, offset, lineHeight, fontAscent;
- Point thePoint;
- Rect viewRect;
- TextStyle style;
-
- if(partCode)
- {
- modalDlgPtr = (*scrollbarHdl)->contrlOwner;
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- editRecHdl = (*docRecHdl)->editRecHdl;
- viewRect = (*editRecHdl)->viewRect;
- thePoint.h = viewRect.left + kTextInset;
-
- switch(partCode)
- {
- case inUpButton:
- // Set delta so that, after the scroll, the top of the incoming line
- // of text will be positioned cleanly at top of the view rectangle
- thePoint.v = viewRect.top - 4;
- offset = TEGetOffset(thePoint,editRecHdl);
- thePoint = TEGetPoint(offset,editRecHdl);
- TEGetStyle(offset,&style,&lineHeight,&fontAscent,editRecHdl);
- delta = thePoint.v - lineHeight - viewRect.top;
- break;
-
- case inDownButton:
- // Set delta so that, after the scroll, the bottom of the incoming line
- // of text will be positioned cleanly at bottom of the view rectangle
- thePoint.v = viewRect.bottom + 2;
- offset = TEGetOffset(thePoint,editRecHdl);
- thePoint = TEGetPoint(offset,editRecHdl);
- delta = thePoint.v - viewRect.bottom;
- break;
-
- case inPageUp:
- // Set delta so that, after the scroll, the top of the top line
- // of text will be positioned cleanly at the top of the view rectangle
- // and the line of text which was previously at the top will still be
- // visible at the bottom of the view rectangle
- thePoint.v = viewRect.top + 2;
- offset = TEGetOffset(thePoint,editRecHdl);
- thePoint = TEGetPoint(offset,editRecHdl);
- TEGetStyle(offset,&style,&lineHeight,&fontAscent,editRecHdl);
- thePoint.v += lineHeight - fontAscent;
- thePoint.v -= viewRect.bottom - viewRect.top;
- offset = TEGetOffset(thePoint,editRecHdl);
- thePoint = TEGetPoint(offset,editRecHdl);
- TEGetStyle(offset,&style,&lineHeight,&fontAscent,editRecHdl);
- delta = thePoint.v - viewRect.top;
- if(offset == 0)
- delta -= lineHeight;
- break;
-
- case inPageDown:
- // Set delta so that, after the scroll, the bottom of the bottom line
- // of text will be positioned cleanly at the bottom of the view rectangle
- // and the line of text which was previously at the bottom will still be
- // visible at the top of the view rectangle
- thePoint.v = viewRect.bottom - 2;
- offset = TEGetOffset(thePoint,editRecHdl);
- thePoint = TEGetPoint(offset,editRecHdl);
- TEGetStyle(offset,&style,&lineHeight,&fontAscent,editRecHdl);
- thePoint.v -= fontAscent;
- thePoint.v += viewRect.bottom - viewRect.top;
- offset = TEGetOffset(thePoint,editRecHdl);
- thePoint = TEGetPoint(offset,editRecHdl);
- TEGetStyle(offset,&style,&lineHeight,&fontAscent,editRecHdl);
- delta = thePoint.v - lineHeight - viewRect.bottom;
- if(offset == (**editRecHdl).teLength)
- delta += lineHeight;
- break;
- }
-
- oldValue = GetCtlValue(scrollbarHdl);
-
- if(((delta < 0) && (oldValue > 0)) || ((delta > 0) &&
- (oldValue < GetControlMaximum(scrollbarHdl))))
- {
- // When this routine is called, TextEdit may have set the clipping region to the
- // viewRect rectangle, so we reset it here to make sure the scroll bar gets drawn.
-
- GetClip(gSavedClipRgn);
- ClipRect(&modalDlgPtr->portRect);
-
- SetControlValue(scrollbarHdl,oldValue + delta);
- SetClip(gSavedClipRgn);
- }
-
- scrollTextAndPicts(modalDlgPtr);
- }
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ scrollTextAndPicts
-
- // Called by handleScrollBar and actionProcedure to scroll the text and pictures into
- // sync with the scroll bar's control value.
-
- void scrollTextAndPicts(DialogPtr modalDlgPtr)
- {
- docRecordHandle docRecHdl;
- TEHandle editRecHdl;
- SInt16 scrollDown, oldScroll;
- Rect updateRect;
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- editRecHdl = (*docRecHdl)->editRecHdl;
-
- oldScroll = (*editRecHdl)->viewRect.top -(**editRecHdl).destRect.top;
- scrollDown = oldScroll - GetCtlValue((*docRecHdl)->scrollbarHdl);
- if(scrollDown == 0)
- return;
-
- TEScroll(0,scrollDown,editRecHdl);
-
- if((*docRecHdl)->pictCount == 0)
- return;
-
- updateRect = (*editRecHdl)->viewRect;
-
- if(scrollDown > 0)
- {
- if(scrollDown < (updateRect.bottom - updateRect.top))
- updateRect.bottom = updateRect.top + scrollDown;
- }
- else
- {
- if( - scrollDown < (updateRect.bottom - updateRect.top))
- updateRect.top = updateRect.bottom + scrollDown;
- }
-
- drawPictures(modalDlgPtr,&updateRect);
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ drawPictures
-
- // Called by drawHelp and scrollTextAndPicts to draw the pictures. For all pictures,
- // checks whether the picture's rectangle is within the update rectangle. If is is,
- // the clipping rectangle is set to the update rectangle and the picture is drawn.
-
- void drawPictures(DialogPtr modalDlgPtr,Rect *updateRect)
- {
- docRecordHandle docRecHdl;
- TEHandle editRecHdl;
- SInt16 pictCount, pictIndex, vOffset;
- PicHandle thePictHdl;
- Rect pictLocRect, dummyRect;
-
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- editRecHdl = (*docRecHdl)->editRecHdl;
-
- vOffset = (*editRecHdl)->destRect.top - (*editRecHdl)->viewRect.top - kTextInset;
- pictCount = (*docRecHdl)->pictCount;
-
- for(pictIndex = 0;pictIndex < pictCount;pictIndex++)
- {
- pictLocRect = (*docRecHdl)->pictInfoRecPtr[pictIndex].bounds;
- OffsetRect(&pictLocRect,0,vOffset);
-
- if(!SectRect(&pictLocRect,updateRect,&dummyRect))
- continue;
-
- thePictHdl = (*docRecHdl)->pictInfoRecPtr[pictIndex].pictureHdl;
-
- LoadResource((Handle) thePictHdl);
- HLock((Handle) thePictHdl);
-
- GetClip(gSavedClipRgn);
- ClipRect(updateRect);
- DrawPicture(thePictHdl,&pictLocRect);
-
- SetClip(gSavedClipRgn);
- HUnlock((Handle) thePictHdl);
- }
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ helpDialogFilter
-
- // Apart from the usual Return and Enter key handling, this filter handles the case of
- // a mouse-down in the scroll bar by calling handleScrollBar.
-
- pascal Boolean helpDialogFilter(DialogPtr modalDlgPtr, EventRecord *eventRecPtr,
- SInt16 *itemHit)
- {
- docRecordHandle docRecHdl;
- SInt16 handledEvent, itemType, thePart;
- SInt8 charCode;
- Rect itemRect;
- Handle itemHdl;
- Point mouseXY;
- SInt32 finalTicks;
- ControlHandle controlHdl;
-
- handledEvent = false;
-
- switch(eventRecPtr->what)
- {
- case keyDown:
- case autoKey:
- charCode = eventRecPtr->message & charCodeMask;
- if((charCode == (SInt8) kReturn) || (charCode == (SInt8) kEnter))
- {
- GetDialogItem(modalDlgPtr,iOK,&itemType,&itemHdl,&itemRect);
- HiliteControl((ControlHandle) itemHdl,inButton);
- Delay(10,&finalTicks);
- HiliteControl((ControlHandle) itemHdl,0);
- handledEvent = true;
- *itemHit = iOK;
- }
- break;
-
- case mouseDown:
- mouseXY = eventRecPtr->where;
- GlobalToLocal(&mouseXY);
- thePart = FindControl(mouseXY,modalDlgPtr,&controlHdl);
- docRecHdl = (docRecordHandle) GetWRefCon(modalDlgPtr);
- if(controlHdl == (*docRecHdl)->scrollbarHdl)
- {
- handleScrollBar(modalDlgPtr,thePart,mouseXY);
- *itemHit = iScrollBar;
- handledEvent = true;
- }
- break;
- }
-
- return handledEvent;
- }
-
- // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ drawButtonOutline
-
- pascal void drawButtonOutline(DialogPtr dialogPtr,SInt16 theItem)
- {
- WindowPtr oldPort;
- PenState oldPenState;
- SInt16 itemType;
- Handle itemHandle;
- Rect itemRect;
- SInt8 buttonOval;
-
- GetPort(&oldPort);
- GetPenState(&oldPenState);
-
- GetDialogItem(dialogPtr,iOK,&itemType,&itemHandle,&itemRect);
- SetPort((*(ControlHandle) itemHandle)->contrlOwner);
- InsetRect(&itemRect,-4,-4);
-
- buttonOval = (itemRect.bottom - itemRect.top) / 2 + 2;
-
- PenPat(&qd.black);
- PenSize(3,3);
- FrameRoundRect(&itemRect,buttonOval,buttonOval);
-
- SetPenState(&oldPenState);
- SetPort(oldPort);
- }
-
- //◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
-
-
-